var contact_index = 0;

var saisie_contact = "<label>Type: </label><select id=\"contact_!CODE_type\"><option value=\"Telephone\">Telephone</option><option value=\"Portable\">Portable</option><option value=\"FAX\">Fax</option><option value=\"SNCF\">SNCF</option><option value=\"Email\">Email</option><option value=\"inconnu\">AUTRE</option></select>, valeur: <input id=\"contact_!CODE_valeur\" type=\"text\"/>, description: <input id=\"contact_!CODE_descr\" type=\"text\"/><img onclick=\"ajoutLigneSaisie('contact')\" src=\"images/add.gif\" alt=\"+\"/><br/>";

function nouveau_contact()
{
	contact_index++;
	var elem = document.getElementById("contactSpan");
	var newDiv = document.createElement("span");
	var ligneHtml = saisie_contact;

	if ( contact_index < 10 )
		ligneHtml = ligneHtml.replace(/!CODE/g, "0" + contact_index);
	if ( 9 < contact_index < 100 )
		ligneHtml = ligneHtml.replace(/!CODE/g, "" + contact_index);

	if (contact_index == 1) {
		var elem2 = document.getElementById("contact_start");
		elem.removeChild(elem2);
		newDiv.innerHTML = ligneHtml; 
		elem.appendChild(newDiv);
	} else {
		newDiv.innerHTML = ligneHtml; elem.appendChild(newDiv);
	}
}

function extrait_contact_json()
{
	var tableau_contact = new Array();
	var temp_contact = new Array(3);
	
	var contact_prefix = "contact_";
	var contact_suffix = ["_type", "_valeur", "_descr"];
	
	for (i = 0; i < contact_index; i++) {
		var ligne_contact = new Array(3);
		for (j = 0; j < 3; j++) {
			if (i < 10) {
				temp_contact[j] = contact_prefix + "0" + (i + 1) + contact_suffix[j];
			} else if (9 < i && i < 100) {
				temp_contact[j] = contact_prefix + (i + 1) + contact_suffix[j];
			}
			ligne_contact[j] = document.getElementById(temp_contact[j]).value;
		}
		tableau_contact[i] = ligne_contact;
	}
	
	return tableau_contact;
}